<?php

namespace App\Domain\HealthRecords\Controllers;

use App\Domain\FamilyMember\RpcService\FamilyMemberInterface;
use App\Domain\HealthHistory\RpcService\HealthHistoryInterface;
use App\Domain\LifeHealth\RpcService\LifeHealthInterface;
use App\Domain\Visitlist\RpcService\VisitlistInterface;
use App\Http\Controllers\Controller;
use App\Supports\Constant\PaginationConst;
use App\Supports\Formatter\ResponseFormatter;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;

class HealthRecordsController extends Controller
{
    public function getList(Request $request, FamilyMemberInterface $familyMember)
    {
        $param = [
            'name' => $request['name'],
            'phone' => $request['phone'],
            'idcard' => $request['idcard'],
        ];
        $data = $familyMember->getByNameAndPhoneAndIdcard($param);
        return $this->success($data);
    }

    public function getvisitlist(Request $request, VisitlistInterface $visitlist)
    {
        $params = [
            'uid' => $request['uid'],
            'currentPage' => $request->input('currentPage', 1),
            'pageSize' => $request->input('pageSize', PaginationConst::PAGE_SIZE),
        ];
        $visitPaginator = $visitlist->list($params);
        $visitPaginator = new LengthAwarePaginator($visitPaginator->items(), $visitPaginator->total(), $visitPaginator->perPage(), $visitPaginator->currentPage());
        //格式化
        $keyMap = [
            'uid' => 'uid',
            'date' => 'date',
            'hospital' => 'hospital',
            'room' => 'room',
            'description' => 'description',
            'diagnosis' => 'diagnosis',
            'diseaseName' => 'diseaseName',
            'type' => '',
            'files' => '',
        ];
        return $this->success(ResponseFormatter::formatterPaginator($visitPaginator, $keyMap));
    }

    public function getSmoke(Request $request, LifeHealthInterface $health)
    {
        $data = $health->getSmoking($request['uid']);
        return $this->success($data);
    }

    public function getDrink(Request $request, LifeHealthInterface $health)
    {
        $data = $health->getDrinking($request['uid']);
        return $this->success($data);
    }

    public function getFlavor(Request $request, LifeHealthInterface $health)
    {
        $data = $health->getFlavor($request['uid']);
        return $this->success($data);
    }

    public function getSleep(Request $request, LifeHealthInterface $health)
    {
        $data = $health->getSleep($request['uid']);
        return $this->success($data);
    }

    public function getSport(Request $request, LifeHealthInterface $health)
    {
        $data = $health->getSport($request['uid']);
        return $this->success($data);
    }

    public function getHistoryOperation(Request $request, HealthHistoryInterface $healthHistory)
    {
        $data = $healthHistory->findByOperationUid($request['uid']);
        return $this->success($data);
    }

    public function findByAllergyUid(Request $request, HealthHistoryInterface $healthHistory)
    {
        $data = $healthHistory->findByAllergyUid($request['uid']);
        return $this->success($data);
    }

    public function findByDiseaseUidAndWhere(Request $request, HealthHistoryInterface $healthHistory)
    {
        $data = $healthHistory->findByDiseaseUidAndWhere($request);
        return $this->success($data);
    }
}
